<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="由程序产生" prop="id">
      <el-input v-model="dataForm.id" placeholder="由程序产生"></el-input>
    </el-form-item>
    <el-form-item label="不动产单元号" prop="realtyunitno">
      <el-input v-model="dataForm.realtyunitno" placeholder="不动产单元号"></el-input>
    </el-form-item>
    <el-form-item label="不动产坐落" prop="zl">
      <el-input v-model="dataForm.zl" placeholder="不动产坐落"></el-input>
    </el-form-item>
    <el-form-item label="不动产面积" prop="mj">
      <el-input v-model="dataForm.mj" placeholder="不动产面积"></el-input>
    </el-form-item>
    <el-form-item label="面积单位" prop="mjdw">
      <el-input v-model="dataForm.mjdw" placeholder="面积单位"></el-input>
    </el-form-item>
    <el-form-item label="不动产地址" prop="bdczl">
      <el-input v-model="dataForm.bdczl" placeholder="不动产地址"></el-input>
    </el-form-item>
    <el-form-item label="区划代码" prop="qxdm">
      <el-input v-model="dataForm.qxdm" placeholder="区划代码"></el-input>
    </el-form-item>
    <el-form-item label="不动产权证号" prop="realtycertno">
      <el-input v-model="dataForm.realtycertno" placeholder="不动产权证号"></el-input>
    </el-form-item>
    <el-form-item label="是否存在权利人信息集:1-存在;0-不存在" prop="isqlrset">
      <el-input v-model="dataForm.isqlrset" placeholder="是否存在权利人信息集:1-存在;0-不存在"></el-input>
    </el-form-item>
    <el-form-item label="是否存在抵押:1-存在;0-不存在" prop="isczdy">
      <el-input v-model="dataForm.isczdy" placeholder="是否存在抵押:1-存在;0-不存在"></el-input>
    </el-form-item>
    <el-form-item label="是否存在查封:1-存在;0-不存在" prop="isczcf">
      <el-input v-model="dataForm.isczcf" placeholder="是否存在查封:1-存在;0-不存在"></el-input>
    </el-form-item>
    <el-form-item label="是否存在在办:1-存在;0-不存在" prop="isczzb">
      <el-input v-model="dataForm.isczzb" placeholder="是否存在在办:1-存在;0-不存在"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          seqno: 0,
          id: '',
          realtyunitno: '',
          zl: '',
          mj: '',
          mjdw: '',
          bdczl: '',
          qxdm: '',
          realtycertno: '',
          isqlrset: '',
          isczdy: '',
          isczcf: '',
          isczzb: ''
        },
        dataRule: {
          id: [
            { required: true, message: '由程序产生不能为空', trigger: 'blur' }
          ],
          realtyunitno: [
            { required: true, message: '不动产单元号不能为空', trigger: 'blur' }
          ],
          zl: [
            { required: true, message: '不动产坐落不能为空', trigger: 'blur' }
          ],
          mj: [
            { required: true, message: '不动产面积不能为空', trigger: 'blur' }
          ],
          mjdw: [
            { required: true, message: '面积单位不能为空', trigger: 'blur' }
          ],
          bdczl: [
            { required: true, message: '不动产地址不能为空', trigger: 'blur' }
          ],
          qxdm: [
            { required: true, message: '区划代码不能为空', trigger: 'blur' }
          ],
          realtycertno: [
            { required: true, message: '不动产权证号不能为空', trigger: 'blur' }
          ],
          isqlrset: [
            { required: true, message: '是否存在权利人信息集:1-存在;0-不存在不能为空', trigger: 'blur' }
          ],
          isczdy: [
            { required: true, message: '是否存在抵押:1-存在;0-不存在不能为空', trigger: 'blur' }
          ],
          isczcf: [
            { required: true, message: '是否存在查封:1-存在;0-不存在不能为空', trigger: 'blur' }
          ],
          isczzb: [
            { required: true, message: '是否存在在办:1-存在;0-不存在不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.seqno = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.seqno) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcbdcxx/info/${this.dataForm.seqno}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.id = data.bdcBdcxx.id
                this.dataForm.realtyunitno = data.bdcBdcxx.realtyunitno
                this.dataForm.zl = data.bdcBdcxx.zl
                this.dataForm.mj = data.bdcBdcxx.mj
                this.dataForm.mjdw = data.bdcBdcxx.mjdw
                this.dataForm.bdczl = data.bdcBdcxx.bdczl
                this.dataForm.qxdm = data.bdcBdcxx.qxdm
                this.dataForm.realtycertno = data.bdcBdcxx.realtycertno
                this.dataForm.isqlrset = data.bdcBdcxx.isqlrset
                this.dataForm.isczdy = data.bdcBdcxx.isczdy
                this.dataForm.isczcf = data.bdcBdcxx.isczcf
                this.dataForm.isczzb = data.bdcBdcxx.isczzb
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/bdc/bdcbdcxx/${!this.dataForm.seqno ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'seqno': this.dataForm.seqno || undefined,
                'id': this.dataForm.id,
                'realtyunitno': this.dataForm.realtyunitno,
                'zl': this.dataForm.zl,
                'mj': this.dataForm.mj,
                'mjdw': this.dataForm.mjdw,
                'bdczl': this.dataForm.bdczl,
                'qxdm': this.dataForm.qxdm,
                'realtycertno': this.dataForm.realtycertno,
                'isqlrset': this.dataForm.isqlrset,
                'isczdy': this.dataForm.isczdy,
                'isczcf': this.dataForm.isczcf,
                'isczzb': this.dataForm.isczzb
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
